package com.warren.test;

import com.warren.entity.User;
import lombok.AllArgsConstructor;

import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;

/**
 * @author warren
 * @create
 * @description
 */
@AllArgsConstructor
public class ExportExcelThread implements Runnable{
    private List<User> data;
    private CountDownLatch countDownLatch;
    private Sheet sheet;
    private Integer startIndex;

    @Override
    public void run() {

    }

    private void doExport() throws IllegalAccessException {
        Iterator<User> iterator = data.iterator();
        Field[] fields = User.class.getDeclaredFields();
        if (startIndex == 0) {
            Row row = sheet.createRow(startIndex);
            for (int i = 0; i < fields.length; i ++) {
                Cell cell = row.createCell(i);
                cell.setCellValue(fields[i].getName());
            }
            startIndex++;
        }

        while (iterator.hasNext()) {
            User use = iterator.next();
            Row row = sheet.createRow(startIndex);
            for (int i = 0; i < fields.length ; i++) {
                Cell cell = row.createCell(i);
                cell.setCellValue(String.valueOf(fields[i].get(use)));
            }
            startIndex++;
        }
    }
}
